#ifndef PROXYSERVER_NETCLIENT_MODULE_H
#define PROXYSERVER_NETCLIENT_MODULE_H

#include "Protocol/Protocol.h"
#include "PluginModule/IProxyServerToWorldModule.h"
#include "PluginModule/IProxyServerNetServerModule.h"
#include "PluginModule/IProxyLogicModule.h"
#include "PluginModule/INetModule.h"
#include "PluginModule/ILogModule.h"
#include "PluginModule/INetClientModule.h"
#include "PluginModule/ISecurityModule.h"
#include "PluginModule/IProxyServerToGameModule.h"
#include "PluginModule/IConfigModule.h"

namespace FragrantGrass
{
	class ProxyServerToWorldModule : public IProxyServerToWorldModule
	{
	public:

		ProxyServerToWorldModule(IPluginManager* p)
		{
			m_pPluginManager = p;
			mLastReportTime = 0;
		}

		virtual bool Init();
		virtual bool Shut();
		virtual bool Execute();

		virtual bool AfterInit();

		virtual void LogReceive(const char* str) {}
		virtual void LogSend(const char* str) {}

		virtual INetClientModule* GetClusterModule();
		virtual bool VerifyConnectData(const std::string& strAccount, const std::string& strKey);

	protected:

		void OnSocketWorldServerEvent(const SOCK nSockIndex, const FG_NET_EVENT eEvent, INet* pNet);

		void Register(INet* pNet);
		void ServerReport();

		void OnSelectServerResultProcess(const SOCK nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen);
		void OnServerInfoProcess(const SOCK nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen);

		void LogServerInfo(const std::string& strServerInfo);

		void OnOtherMessage(const SOCK nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen);
	private:
		struct ClientConnectData
		{
			ClientConnectData()
			{
				strAccount = "";
				strConnectKey = "";
			}

			std::string strAccount;
			std::string strConnectKey;
		};

		typedef std::map<std::string, FG_SHARE_PTR<ClientConnectData>> ClientConnectMap;
		ClientConnectMap mWantToConnectMap;

	private:
		INT64 mLastReportTime;

		ILogModule* m_pLogModule;
		IProxyLogicModule* m_pProxyLogicModule;
		IProxyServerNetServerModule* m_pProxyServerNet_ServerModule;
		INetClientModule* m_pNetClientModule;
		ISecurityModule* m_pSecurityModule;
		IConfigModule* m_pConfigModule;

	};
}

#endif//PROXYSERVER_NETCLIENT_MODULE_H